package com.xlh;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.lang.Console;

import java.nio.file.Files;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class ReadFiles {


    public static void main(String[] args) {

        List<String> strings = FileUtil.readLines("C:\\Users\\Administrator\\Downloads\\cdn.ithyxy.com_2022_01_03_120000_121000", "utf-8");
        Map<String, Integer> map = new HashMap<>();
        for (int i = 0; i <strings.size(); i++) {

            String s = strings.get(i);
            String[] split = s.split(" ");
            for (int j = 0; j <split.length; j++) {
                if(split[j].contains("cdn.ithyxy.com")){
                    Integer integer = map.get(split[j]);
                    if(integer == null){
                        map.put(split[j], 1);
                    }else{
                        map.put(split[j], integer++);
                    }
                }
            }
        }

        for (String url : map.keySet()) {
            Integer integer = map.get(url);
            Console.log("请求的URL：" + url +"请求次数："+ integer);
        }
    }


    public static <K extends Comparable, V extends Comparable> Map<K, V> sortMapByValues(Map<K, V> aMap) {
        HashMap<K, V> finalOut = new LinkedHashMap<>();
        aMap.entrySet()
                .stream()
                .sorted((p1, p2) -> p2.getValue().compareTo(p1.getValue()))
                .collect(Collectors.toList()).forEach(ele -> finalOut.put(ele.getKey(), ele.getValue()));
        return finalOut;
    }

}
